#!/bin/bash
# Description: initiate ovs network setting 
# Author: zhangchiqian@uniontech.com
# version: 1.0
# date: 2022-1-6

nmcli c add type ovs-bridge conn.interface br-bond0 con-name br-bond0
nmcli c add type bond-slave con-name bond0-slave1 ifname enp1s0f0 master bond0 autoconnect yes
nmcli c add type bond-slave con-name bond0-slave2 ifname enp2s0f0 master bond0 autoconnect yes
nmcli c add type ovs-port conn.interface br-bond0-int master br-bond0 con-name br-bond0-int
nmcli c add type bond conn.interface bond0 master br-bond0-int con-name br-bond0-bond0-int bond.options mode=802.3ad  autoconnect yes 
nmcli c add type vlan con-name bond0.201 dev bond0 id 201 ipv4.addresses 100.108.5.73/24 ipv4.gateway 100.108.5.254 ipv4.method manual autoconnect yes
nmcli c up br-bond0-bond0-int
# create patch interface
ovs-vsctl add-port br-bond0 br-bond0--br-ex
ovs-vsctl set interface br-bond0--br-ex type=patch
ovs-vsctl add-port br-bond0 br-bond0--br-prv
ovs-vsctl set interface br-bond0--br-prv type=patch

nmcli c add type ovs-bridge conn.interface br-ex con-name br-ex
nmcli c add type ovs-port conn.interface br-ex-port.202 master br-ex ovs-port.tag 202 con-name br-ex-port.202
nmcli c add type ovs-interface slave-type ovs-port conn.interface br-ex-port.202 master br-ex-port.202 con-name br-ex.202
nmcli c modify br-ex.202 ipv4.method static ipv4.addresses 100.108.6.73/24 ipv4.gateway 100.108.6.254 autoconnect yes
nmcli c up br-ex.202
# create patch interface
ovs-vsctl add-port br-ex br-ex--br-bond0
ovs-vsctl set interface br-ex--br-bond0 type=patch

ovs-vsctl add-br br-prv
# create patch interface
ovs-vsctl add-port br-prv br-prv--br-bond0
ovs-vsctl set interface br-prv--br-bond0 type=patch

# let patch interface connect to each other
ovs-vsctl set interface br-bond0--br-ex options:peer=br-ex--br-bond0
ovs-vsctl set interface br-bond0--br-prv options:peer=br-prv--br-bond0
ovs-vsctl set interface br-prv--br-bond0 options:peer=br-bond0--br-prv
ovs-vsctl set interface br-ex--br-bond0 options:peer=br-bond0--br-ex
